﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.AssetManage;


namespace AssetManageSystem.ViewModel.AssetManage.AssetBorrowVMs
{
    public partial class AssetBorrowListVM : BasePagedListVM<AssetBorrow_View, AssetBorrowSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridAction>();
            }
            else
            {
                return new List<GridAction>
            {
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-green"),
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-blue"),
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-8"),
                // this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-orange"),
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                // this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-4"),
                this.MakeStandardAction("AssetBorrow", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "AssetManage").SetButtonClass("btn-col-4"),
            };
            }
        }


        protected override IEnumerable<IGridColumn<AssetBorrow_View>> InitGridHeader()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridColumn<AssetBorrow_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Unit),
                this.MakeGridHeader(x => x.Contacts),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeader(x => x.ReturnDate),
                };
            }
            else
            {
                return new List<GridColumn<AssetBorrow_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Unit),
                this.MakeGridHeader(x => x.Contacts),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeader(x => x.ReturnDate),
                this.MakeGridHeaderAction(width: 200)
            };
            }
        }

        public override IOrderedQueryable<AssetBorrow_View> GetSearchQuery()
        {
            var query = DC.Set<AssetBorrow>()
                .CheckContain(Searcher.Name, x => x.Name)
                .CheckContain(Searcher.Unit, x => x.Unit)
                .CheckContain(Searcher.Contacts, x => x.Contacts)
                .CheckEqual(Searcher.AssetId, x => x.AssetId)
                .CheckBetween(Searcher.OutDate?.GetStartTime(), Searcher.OutDate?.GetEndTime(), x => x.OutDate, includeMax: false)
                .Select(x => new AssetBorrow_View
                {
                    ID = x.ID,
                    DocNumber = x.DocNumber,
                    Name = x.Name,
                    Unit = x.Unit,
                    Contacts = x.Contacts,
                    OutDate = x.OutDate,
                    ReturnDate = x.ReturnDate,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class AssetBorrow_View : AssetBorrow
    {

    }
}
